package com.minidb.sql_compliler;

import java.util.List;

public class ASTNode {
    //抽象语法树节点(AST)
    //解析不同sql
    public String type; //节点类型


    public static class ColumnDef  {
        public String name;
        public String dataType;
        public ColumnDef(String name, String dataType) {
            this.name = name;
            this.dataType = dataType;
        }

        @Override
        public String toString() {
            return name + ": " + dataType;
        }
    }

    // 创建表节点
    public static class CreateTableNode extends ASTNode {
        public String tableName;
        public List<ColumnDef>columns;
        public CreateTableNode(String tableName, List<ColumnDef> columns) {
            this.type = "create_table";
            this.tableName = tableName;
            this.columns = columns;
        }

        @Override
        public String toString() {
            return "CreateTableNode(" +
                    tableName + ',' +
                    columns +
                    ')';
        }
    }

    // 插入节点
    public static class InsertNode extends ASTNode {
        public String tableName;
        public List<String> values;
        public InsertNode(String tableName, List<String> values) {
            this.type = "insert";
            this.tableName = tableName;
            this.values = values;
        }

        @Override
        public String toString() {
            return "Insert(" + tableName + ", " + values + ")";
        }
    }
}
